package org.gwt.grin.client.input;

import org.gwt.grin.client.Node;
import org.gwt.grin.client.Segment;
import org.gwt.grin.client.Show;

/**
 * Superclass for input handlers (some also handle mouse events).
 * 
 * @author Bill Foote (http://jovial.com)
 * @author ggeorg
 */
public abstract class RCHandler implements Node {

	protected Show show;
	protected String name;

	public RCHandler() {
		// do nothing
	}

	public void setShow(Show show) {
		this.show = show;
	}

	public String toString() {
		String nm = getClass().getName();
		int i = nm.lastIndexOf('.');
		if (i >= 0) {
			nm = nm.substring(i + 1, nm.length());
		}
		return nm;
	}

	/**
	 * Returns the name of this RCHandler, if known. All public handlers have
	 * names; private handlers might not.
	 */
	public String getName() {
		return name;
	}


	/**
	 * Handle a remote control key press.
	 * 
	 * @return true if the keypress is used
	 **/
	public abstract boolean handleKeyPressed(RCKeyEvent ke, Show caller);

	/**
	 * Handle a remote control key release.
	 * 
	 * @return true if the keypress is used
	 **/
	public abstract boolean handleKeyReleased(RCKeyEvent ke, Show caller);

	/**
	 * @return true if something is done with the mouse
	 **/
	public abstract boolean handleMouse(int x, int y, boolean activate);

	/**
	 * Called for handlers in s when s is activated
	 **/
	public abstract void activate(Segment s);

	/**
	 * Called by the show to let us know as the model progresses through time.
	 * This can be useful for things like timeouts.
	 **/
	public abstract  void nextFrame();

}
